package com.twh.www.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.twh.www.entity.WnAdmin;
import com.twh.www.entity.WnUser;
import com.twh.www.service.WnAdminService;
import com.twh.www.mapper.WnAdminMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;


@Service
public class WnAdminServiceImpl extends ServiceImpl<WnAdminMapper, WnAdmin> implements WnAdminService {

    @Autowired
    private WnAdminMapper adminMapper;

    @Override
    public WnAdmin login(String account, String password) {
        return adminMapper.getAdminByAccount(account);
    }

    @Override
    public List<WnUser> getAllUser() {
        return adminMapper.getAllUser();
    }

    @Override
    public List<WnAdmin> getAllAdmin() {
        return adminMapper.getAllAdmin();
    }

    @Override
    public boolean freezeAdmin(Integer id) {
        return adminMapper.updateAdminStatus(id, "2") > 0;
    }

    @Override
    public boolean unfreezeAdmin(Integer id) {
        return adminMapper.updateAdminStatus(id, "0") > 0;
    }

    @Override
    public boolean addToBlacklistAdmin(Integer id) {
        return adminMapper.updateAdminStatus(id, "3") > 0;
    }

    @Override
    public boolean removeFromBlacklistAdmin(Integer id) {
        return adminMapper.updateAdminStatus(id, "0") > 0;
    }

    @Override
    public boolean deleteAdmin(Integer id) {
        return adminMapper.updateAdminStatus(id, "4") > 0; // 修改为更新状态为 4
    }

    @Override
    public WnAdmin getAdminByAccount(String account) {
        return adminMapper.getAdminByAccount(account);
    }

    @Override
    public boolean updateAdminAccount(WnAdmin admin) {
        return adminMapper.updateAdminAccount(admin) > 0;
    }

    @Override
    public boolean updateAdminPassword(WnAdmin admin) {
        return adminMapper.updateAdminPassword(admin) > 0;
    }


    @Override
    public boolean save(WnAdmin admin) {
        return super.save(admin);
    }
}




